﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace canyinguanlixitong
{
    public partial class frmupdatesever : Form
    {
        public frmupdatesever()
        {
            InitializeComponent();
        }
        public int stu;
        string strconn = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
        private void frmupdatesever_Load(object sender, EventArgs e)
        {
            dzh();
        }
        public void dzh() {
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            string sql = "select fwsbh, fwsdj from dbo.fws where fwsbh='"+stu+"'and fwsbh='"+stu+"'";
            SqlCommand cmd = new SqlCommand(sql,conn);
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                textBox1.Text = reader["fwsbh"].ToString();
                textBox2.Text = reader["fwsdj"].ToString();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            int bianhao = Convert.ToInt32(this.textBox1.Text);
            string dj = this.textBox2.Text;
            string sql = "update dbo.fws set fwsbh='"+bianhao+"',fwsdj='"+dj+"'";
            SqlCommand cmd = new SqlCommand(sql,conn);
            int i=cmd.ExecuteNonQuery();
            if (i>0)
            {
                MessageBox.Show("修改成功");
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }  
    }
}
